//
//  NewsTableViewCell.m
//  B-72K
//
//  Created by sos on 16/3/7.
//  Copyright © 2016年 sos. All rights reserved.
//

#import "NewsTableViewCell.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
#import "LMTTImeChuo.h"

#import "AllPrefixHeader.pch"

@implementation NewsTableViewCell



// 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatdata];
        
    }
    return self;
}
- (void)creatdata
{
    UIImageView *touxiang = [UIImageView new];
    [self.contentView addSubview:touxiang];
    touxiang.layer.cornerRadius = 20;
    touxiang.clipsToBounds = YES;
    self.touxiang = touxiang;
    
    UILabel *name = [UILabel new];
    [self.contentView addSubview:name];
    _name.font = [UIFont systemFontOfSize:12];

    self.name = name;
    [_name NightWithType:UIViewColorTypeNormal];
    
    UILabel *title = [UILabel new];
    [self.contentView addSubview:title];
    title.numberOfLines = 0;
    self.title = title;
    [_title NightWithType:UIViewColorTypeNormal];
    
    
    UILabel *columName = [UILabel new];
    [self.contentView addSubview:columName];
    columName.textAlignment = NSTextAlignmentRight;
    self.columName = columName;
    [_columName NightWithType:UIViewColorTypeNormal];
    
    UIImageView *tu = [UIImageView new];
    [self.contentView addSubview:tu];
    self.tu = tu;
    
    UIView *shu = [UIView new];
    [self.contentView addSubview:shu];
    self.shu = shu;
    
    UILabel *time = [UILabel new];
    [self.contentView addSubview:time];
    self.time = time;
    [_time NightWithType:UIViewColorTypeNormal];
    
    __weak __typeof(&*self)weakSelf = self;

    [self.touxiang mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(40);
        make.top.equalTo(weakSelf.mas_top).offset(5);
        make.left.equalTo(weakSelf.mas_left).offset(10);
    }];
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(75);
        make.top.equalTo(weakSelf.mas_top).offset(15);
        make.left.equalTo(self.touxiang.mas_right).offset(5);
        
        
    }];
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(80);
        make.top.equalTo(weakSelf.mas_top).offset(15);
        make.left.equalTo(self.name.mas_right).offset(5);
        
        
    }];
    [self.columName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(70);
        make.top.equalTo(weakSelf.mas_top).offset(15);
        make.left.equalTo(weakSelf.mas_right).offset(-80);
        
        
    }];
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.touxiang.mas_bottom).offset(1);
        make.left.equalTo(weakSelf.mas_left).offset(10);
        make.bottom.equalTo(weakSelf.mas_bottom).offset(-10);
        make.right.equalTo (tu.mas_left).offset (-10);
        
        
    }];
    [self.tu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(100);
        make.width.mas_equalTo(110);
        make.top.equalTo(self.touxiang.mas_bottom).offset(0);
        make.right.equalTo(weakSelf.mas_right).offset(-10);
    }];
 }
// 重写model的setter方法
- (void)setNews:(NewsModel *)news
{
    _news = news;
    _title.text = news.title;
    _columName.text = news.columnName;
    _name.text = news.name;
    // [cell.tu sd_setImageWithURL:[NSURL URLWithString:m.featureImg]];
    [_tu sd_setImageWithURL:[NSURL URLWithString:news.featureImg] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
    [_touxiang sd_setImageWithURL:[NSURL URLWithString:news.avatar]];
    _time.text = [LMTTImeChuo compareCurrentTime:news.publishTime];

    
}

//-(void)layoutSubviews{
//    [super layoutSubviews];
//    
//    
//    __weak __typeof(&*self)weakSelf = self;
//    
//    [self.touxiang mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(40);
//        make.width.mas_equalTo(40);
//        make.top.equalTo(weakSelf.mas_top).offset(5);
//        make.left.equalTo(weakSelf.mas_left).offset(10);
//    }];
//    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(20);
//        make.width.mas_equalTo(75);
//        make.top.equalTo(weakSelf.mas_top).offset(15);
//        make.left.equalTo(weakSelf.touxiang.mas_right).offset(5);
//        
//        
//    }];
//    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(20);
//        make.width.mas_equalTo(80);
//        make.top.equalTo(weakSelf.mas_top).offset(15);
//        make.left.equalTo(weakSelf.name.mas_right).offset(5);
//        
//        
//    }];
//    [self.columName mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(20);
//        make.width.mas_equalTo(70);
//        make.top.equalTo(weakSelf.mas_top).offset(15);
//        make.left.equalTo(weakSelf.mas_right).offset(-80);
//        
//        
//    }];
//    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(weakSelf.touxiang.mas_bottom).offset(1);
//        make.left.equalTo(weakSelf.mas_left).offset(10);
//        make.bottom.equalTo(weakSelf.mas_bottom).offset(-10);
//        make.right.equalTo (weakSelf.tu.mas_left).offset (-10);
//        
//        
//    }];
//    [self.tu mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo(100);
//        make.width.mas_equalTo(110);
//        make.top.equalTo(weakSelf.touxiang.mas_bottom).offset(0);
//        make.right.equalTo(weakSelf.mas_right).offset(-10);
//    }];
//    
//
//
//}








/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
